$(function() {
    $('.register-button').click(function() {
        var
            password = $("#regPass").val(),
            regcode = $("#regCode").val();
        if (verMobile() === 1) {
            return;
        }
        if (regcode == "") {
            promptMsg("请输入手机短信验证码！");
            return;
        }
        if (password == null || password == "") {
            promptMsg("请输入设置的密码！");
            return;
        } else if (password.length < 6 || password.length > 10) {
            promptMsg("密码长度在6-10位之间！");
            return;
        }


    })

    $('.login-code').click(function() {
        if (verMobile() === 1) {
            return;
        }
        var t = $(this);

        if (t.hasClass('disabled')) {
            console.log('1')
        } else {
            t.text("正在发送验证码...").addClass('disabled');
            var $num = 120,
                starTime = setInterval(function() {
                    $num--;
                    $num = $num < 0 ? 0 : $num;
                    t.text($num + "s后重试").addClass('disabled');
                    if ($num === 0) {
                        clearInterval(starTime);
                        t.text("重新获取").removeClass('disabled');
                    }
                }, 1000);
        }
    })
})

function verMobile() {
    var mobile = $('#regMobile').val(),
        reg = /^1[34578]\d{9}$/;
    if (!mobile) {
        promptMsg('请输入您的手机号码');
        return 1;
    } else if (!reg.test(mobile)) {
        promptMsg('请输入正确格式的手机号码');
        return 1;
    }
}

function promptMsg(t) {
    var p = $('.login-prompt');
    p.text(t).css('visibility', 'visible');
    setTimeout(function() {
        p.css('visibility', 'hidden');
    }, 3000)
}